<include file="Public/head" />
<link type="text/css" rel="stylesheet" href="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.css" />
<script src="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.js" type="text/javascript"></script>
<style type='text/css'>
    .rule_config{width:100%;}
    .rule_config  .rc{width:100%;height:50px; line-height:50px;}
    .rule_config  .rc_l{width:10%;float:left;}
    .rule_config  .rc_r{width:80%;text-align:left;}
    .c_input{border: 1px solid #d7d7d7;height: 24px;line-height: 24px;margin: 0 10px 10px 0;text-align: center;width: 150px;}
</style>
</head>
<include file="Public/common_header" />
<div class="mian">
    <include file="Public/sidebar"  menu="jjr.hbgl" />
    <div class="mianR">
        <h3 class="cha">红包管理</h3>
        <div class='rule_config'>
            <div class='rc'>
                <div class='rc_l'><b>红包金额</b></div>
                <div class='rc_r'>
                    <input type='text' name='commission_money' class='c_input' value='{$data.amount}' placeholder='请输入红包金额'> 单位为元
                </div>
                <div class='clear'></div>
            </div>
            <div class='rc'>
                <div class='rc_l'><b>分成比例</b></div>
                <div class='rc_r'>
                    <input type='text' name='agent_per' class='c_input' value='{$data.agent_per}' placeholder='请输入经纪人占比' maxlength="3"> 至&nbsp;&nbsp;
                    <input type='text' name='superior_per' class='c_input' value='{$data.superior_per}' placeholder='请输入上级占比' maxlength="3"> 单位为百分比
                </div>
            </div>
        </div>
        <div class="yongBtn">
            <input class="queding confirm" type="button" value="确定">
            <input class="quxiao" type="button" value="返回" onclick="history.back();">
        </div>
    </div>
    <div class="clear"></div>
</div>
<script type="text/javascript">
   $(function(){
       $("input[name='commission_money']").change(function(){
           var commission_money = $(this).val();
           if(!/(^[0-9]\d*$)/.test(commission_money)){
                shibai_alert('红包金额格式不正确');
                return false;
           }
       });
       $("input[name='agent_per']").change(function(){
            var agent_per = $(this).val();
            if (!/^(?:0|[1-9][0-9]?|100)$/.test(agent_per)) {
                shibai_alert('分成比例不正确');
                return false;
            }
            var superior_per = 100 - agent_per;
            $("input[name='superior_per']").val(superior_per);
       });
       $("input[name='superior_per']").change(function(){
            var superior_per = $(this).val();
            if (!/^(?:0|[1-9][0-9]?|100)$/.test(superior_per)) {
                shibai_alert('分成比例不正确');
                return false;
            }
            var agent_per = 100 - superior_per;
            $("input[name='agent_per']").val(agent_per);
       });
       
      $('.confirm').on('click',function(){
            var commission_money = $("input[name='commission_money']").val();
            var agent_per = $("input[name='agent_per']").val();
            var superior_per = $("input[name='superior_per']").val();
            var post_data = {
                'commission_money':commission_money,
                'agent_per':agent_per,
                'superior_per':superior_per
            }
            $.post("/Commission/update_rule_config", post_data, function (data) {
                if(data.code == 200){
                    btn_alert('更新成功');
                }
                shibai_alert(data.msg);
            }, "JSON");
      }); 
   });
</script>
<include file="Public/foot" />
